//
//  FeedbackController.m
//  SleepingElf
//
//  Created by karong on 2023/10/26.
//

#import "FeedbackController.h"
#import "FeedbackRequest.h"

@interface FeedbackController () <UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet YYTextView *contentTV;
@property (weak, nonatomic) IBOutlet UITextField *contactTF;
@end

@implementation FeedbackController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:WSLocalized(@"输入正确的 QQ号 /  手机号 （选填）") attributes:@{NSForegroundColorAttributeName:[UIColor colorFromHexRGB:@"8691C7"], NSFontAttributeName:[UIFont systemFontOfSize:16]}];
    self.contactTF.attributedPlaceholder = attrString;
    self.contentTV.placeholderText = WSLocalized(@"输入您遇到的详细问题或建议");
}

- (void)submitRequest {
    [FeedbackRequest submitFeedbackWithContent:self.contentTV.text contact:self.contactTF.text success:^{
        [SEToast simple:WSLocalized(@"感謝您的反饋，我們會盡快處理")];
        [self.navigationController popViewControllerAnimated:YES];
        } failed:^(NSURLResponse * _Nonnull response, NSError * _Nonnull error, id  _Nonnull responseObject) {
            
        }];
}

- (IBAction)submitAction:(id)sender {
    if (SEIsNullOrEmpty(self.contentTV.text)) {
        [SEToast simple:self.contentTV.placeholderText];
        return;
    }
    [self submitRequest];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [self.view endEditing:YES];
    return YES;
}
@end
